package edu.csci3308.mckeevek.flashcards.test;

import static org.junit.Assert.*;

import static org.junit.Assert.*;
import junit.framework.Assert;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.csci3308.mckeevek.flashcards.FlashCardServlet;

public class FlashCardsTest1 {

	FlashCardServlet testMe = new FlashCardServlet();
	String fs = System.getProperty("file.separator");
	File file = new File(System.getProperty("user.home") + fs + "CSCI3308_FlashCards_McKeever" + fs + "flashCardDecks.txt");
	ArrayList<String> deck = new ArrayList<String>();
	@Test
	public void deckTest() {
		Assert.assertTrue(deck.isEmpty()); 
		deck.add("FrontA,BackA");
		deck.add("FrontB,BackB");
		deck.add("FrontC,BackC");
		testMe.saveDeck(deck);
		deck.clear();
		Assert.assertTrue(deck.isEmpty()); 
		deck = testMe.loadDeck();
		Assert.assertTrue(!deck.isEmpty()); 
		deck.clear();
	}
		
	//@Test
	//public void pageTest() {
		//HttpServletRequest request = new HttpServletRequest(); //cannot instantiate HttpServlet....
		//testMe.determinePage(request);
	//}
	
	@Test
	public void buttonTest() {
		String buttonName; 
		buttonName = "Random Card";
		Assert.assertTrue(testMe.determineButton(buttonName) == 1);
		buttonName = "Next Card";
		Assert.assertTrue(testMe.determineButton(buttonName) == 2);
		buttonName = "Prev Card";
		Assert.assertTrue(testMe.determineButton(buttonName) == 3);
		buttonName = "Flip Card";
		Assert.assertTrue(testMe.determineButton(buttonName) == 7);
		buttonName = "Add Card";
		Assert.assertTrue(testMe.determineButton(buttonName) == 4);
		buttonName = "Remove Card";
		Assert.assertTrue(testMe.determineButton(buttonName) == 5);
		buttonName = "Submit";
		Assert.assertTrue(testMe.determineButton(buttonName) == 6);
		buttonName = "Search Deck";
		Assert.assertTrue(testMe.determineButton(buttonName) == 8);
		buttonName = "Search";
		Assert.assertTrue(testMe.determineButton(buttonName) == 9);
	}

}
